package com.worthtech.billportal.dao.hibernate;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.worthtech.billportal.bean.Organization;
import com.worthtech.billportal.dao.OrganizationDAO;

public class OrganizationHibernateDAO extends HibernateDaoSupport implements OrganizationDAO {

	public List getOrganizationList() {
		return this.getHibernateTemplate().find("from Organization order by organizationCode");
	}

	public List getOrganizationList(String organizationCode) {
		if(StringUtils.isEmpty(organizationCode)){
			return this.getHibernateTemplate().find("from Organization where parentCode is null");
		}
		return this.getHibernateTemplate().find("from Organization where parentCode = ?",organizationCode);
		
	}

	public Organization getOrganization(String organizationCode) {
		return (Organization)this.getHibernateTemplate().get(Organization.class,organizationCode);
	}

}
